package org.techmore.bussiness;

import java.util.List;

import org.techmore.common.utils.activity.ActivityUtils;
import org.techmore.common.utils.sound.SoundPoolUtils;
import org.techmore.hakka.R;
import org.techmore.hakka.VisitorSoundActivity;
import org.techmore.valueobject.GridViewVO;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

public class GridPartAvtivityHandler {
	
	private static GridPartAvtivityHandler gridPartAvtivityHandler = new GridPartAvtivityHandler();

	public static GridPartAvtivityHandler getInstance() {
		return gridPartAvtivityHandler;
	}

	
	
	public class GridViewAdapter extends BaseAdapter {
		
		private Context context;
		private Activity activity;
		private List<GridViewVO> list = null;
		
		public GridViewAdapter(Context context,Activity activity,List<GridViewVO> list) {
			this.context = context;
			this.list = list;
			this.activity = activity;
		}
		@Override
		public int getCount() {
			return list.size();
		}
		@Override
		public Object getItem(int arg0) {
			return list.get(arg0);
		}
		@Override
		public long getItemId(int arg0) {
			return arg0;
		}
		@Override
		public View getView(int arg0, View arg1, ViewGroup arg2) {
			LinearLayout linearLayout = new LinearLayout(context);
			linearLayout.setBackgroundResource(R.drawable.circle_background);
			linearLayout.setOrientation(LinearLayout.VERTICAL);

			ImageView iv = new ImageView(context);
			iv.setImageBitmap(((BitmapDrawable)context.getResources().getDrawable(list.get(arg0).getImageId())).getBitmap());
			LinearLayout.LayoutParams params2 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			params2.gravity=Gravity.CENTER;
			linearLayout.addView(iv, params2);
			
			TextView tv = new TextView(context);
			tv.setText(list.get(arg0).getName());
			LinearLayout.LayoutParams params3 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			params3.gravity=Gravity.CENTER;
			
			linearLayout.addView(tv, params3);
			
			linearLayout.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					SoundPoolUtils.getInstance(context).playSound(SoundPoolUtils.SOUND_BUTTON_CLICK);
					ActivityUtils.getInstance().leftIN_rightOUT_Transition(activity, context, VisitorSoundActivity.class);
				}
			});
			
			
			return linearLayout;
		}
	}

}
